package com.woniuxy.creditsystem.customermag.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.creditsystem.common.bean.CustomerInfo;
import com.woniuxy.creditsystem.common.bean.DtoCus;

import com.woniuxy.creditsystem.common.bean.TableResult;
import com.woniuxy.creditsystem.common.util.PageRest;
import com.woniuxy.creditsystem.common.util.ResultMsg;
import com.woniuxy.creditsystem.customermag.service.ICustomerService;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @author ：zhengbin
 * @date ：Created in 2020/12/12 0012
 * @description：
 * @modified By：
 * @version: $
 */
@RequestMapping("customer")
@RestController
public class CustomerController {

    @Resource
    private ICustomerService customerServiceImpl;


    @ResponseBody
    @GetMapping(value = "/all",produces = "application/json;charset=utf-8")
    public ResultMsg<List<DtoCus>> findAll(){
        ResultMsg<List<DtoCus>>  resultMsg = new ResultMsg<List<DtoCus>> ();

        resultMsg.setData(customerServiceImpl.findAll());
        resultMsg.setCode(200);
        resultMsg.setMsg("操作成功");
        return  resultMsg;

    }
    @ResponseBody
    @GetMapping(value = "/one",produces = "application/json;charset=utf-8")
    public ResultMsg findOneById(@RequestParam("cid")long id){
        System.out.println("用户id:"+id);
        ResultMsg<CustomerInfo>  resultMsg = new ResultMsg<CustomerInfo> ();
        resultMsg.setData(customerServiceImpl.findById(id));
        resultMsg.setCode(200);

        return resultMsg;

    }

    //分页查询
    @ResponseBody
    @GetMapping(value = "/page",produces = "application/json;charset=utf-8")
    public TableResult<DtoCus> findByParams(PageRest pageRest, DtoCus dtoCus){
    //String name = request.getParameter("name");
        System.out.println("条件查询");
       // System.out.println("name:"+name);
     //long loanStatus= Integer.parseInt();
        System.out.println(pageRest);

       // DtoCus dtoCus=new DtoCus();
        System.out.println(dtoCus);
        PageInfo<DtoCus> pageInfo= customerServiceImpl.findByParams(pageRest,dtoCus);
        System.out.println(pageInfo);
                System.out.println(pageInfo.getTotal());

        return new TableResult<DtoCus>(pageInfo.getTotal(),pageInfo.getList());
    }

    @PutMapping(value = "/cancelFri",produces = "application/json;charset=utf-8")
    public ResultMsg updateStatus(@RequestParam("cid")long id){
        ResultMsg msg = new ResultMsg();
        int rest=customerServiceImpl.updatestatus(id);
        if(rest>=0){
            msg.setCode(200);
            msg.setMsg("修改成功");
        }

        return msg;
    }

    @PutMapping(value ="/updateMark",produces = "application/json;charset=utf-8")
    public ResultMsg updateRemarks(DtoCus dtoCus){
        System.out.println(dtoCus );
        ResultMsg msg = new ResultMsg();
        int rest=customerServiceImpl.updatestRemark(dtoCus);
        if(rest>=0){
            msg.setCode(200);
            msg.setMsg("修改成功");
        }

        return msg;

    }
}
